package com.xyq.fs.views;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Random;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;

public class WindowsHelp {

	static Random rd = new Random();

	public static void init(){}
	public static ImageView tk = new ImageView(getImage(1));
	public static Image tkk = getImage(1);
	public static Image xtb = getImg();
	
	public static Image getImage(int n){
		
		File[] flist = new File(System.getProperty("user.dir") + "\\CONF\\IMAGES\\").listFiles();
		try {
			return new Image(new BufferedInputStream(new FileInputStream(flist[n]), 1024 * 1024 * 100));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static Background getImgUrl(int n) {

		File[] flist = new File(System.getProperty("user.dir") + "\\CONF\\IMAGES\\").listFiles();
		n = 0;
		if (flist == null || flist.length == 0) {
			return null;
		} else {
			BackgroundImage myBI = null;
			try {
				myBI = new BackgroundImage(
						new Image(new BufferedInputStream(new FileInputStream(flist[n]), 1024 * 1024 * 100)),
						BackgroundRepeat.REPEAT, BackgroundRepeat.REPEAT, BackgroundPosition.DEFAULT,
						BackgroundSize.DEFAULT);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			return new Background(myBI);
		}
	}

	public static Image getImg() {

		File[] flist = new File(System.getProperty("user.dir") + "\\CONF\\IMAGES2\\").listFiles();
		if (flist == null || flist.length == 0) {
			return null;
		} else {
			try {
				return new Image(new FileInputStream(flist[0]));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public static Image getsb() {

		File[] flist = new File(System.getProperty("user.dir") + "\\CONF\\IMAGES2\\").listFiles();
		if (flist == null || flist.length == 0) {
			return null;
		} else {
			try {
				return new Image(new BufferedInputStream(new FileInputStream(flist[1]), 1024 * 1024 * 100));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	/**
	 * 扫描点击事件
	 */
	public static void onSaoMiao() {

	}

}
